<template>
  <el-card>
    <div class="order-management">
      <h2>我的订单</h2>
      <div v-if="orders.length > 0" class="order-list">
        <div v-for="order in orders" :key="order.id" class="order-item">
          <div class="order-details">
            <p><strong>订单编号:</strong> {{ order.id }}</p>
            <p><strong>订单日期:</strong> {{ order.date }}</p>
            <p><strong>订单状态:</strong> {{ order.status }}</p>
          </div>
          <div class="order-actions">
            <button @click="viewOrderDetails(order.id)">查看订单详情</button>
          </div>
        </div>
      </div>
      <div v-else class="no-orders">
        <p>您还没有任何订单。</p>
      </div>
    </div>
  </el-card>

</template>

<script>
export default {
  data() {
    return {
      orders: [
        { id: '12345', date: '2023-10-01', status: '已发货' },
        { id: '67890', date: '2023-10-05', status: '待发货' },
        // 可以根据需要添加更多订单
      ]
    };
  },
  methods: {
    viewOrderDetails(orderId) {
      // 这里可以添加跳转到订单详情页面的逻辑
      alert(`查看订单详情: ${orderId}`);
    }
  }
};
</script>

<style scoped>
.order-management {
  padding: 20px;
}

.order-list {

  margin: 0 auto; /* 使订单列表水平居中 */
  max-width: 800px; /* 设置最大宽度 */
  text-align: left; /* 使订单项内容左对齐 */
}

.order-item {
  border: 1px solid #ccc;
  padding: 10px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-details p {
  margin: 5px 0;
}

.order-actions button {
  padding: 5px 10px;
  background-color: #007bff;
  color: white;
  border: none;
  cursor: pointer;
}

.order-actions button:hover {
  background-color: #0056b3;
}

.no-orders {
  margin-top: 20px;
  text-align: center;
  color: #666;
}
</style>
